﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace FluentData
{
    internal  partial class ActionsHandler
    {
        internal void AutoMapColumnsAction(params string[] ignorePropertyNames)
        {
            VerifyAutoMapAlreadyCalled();

            var properties = ReflectionHelper.GetProperties(_data.Item.GetType());
            var set = new HashSet<string>();
            foreach (var name in ignorePropertyNames)
            {
                set.Add(name);
            }

            foreach (var property in properties)
            {
                var ignoreProperty = set.SingleOrDefault(x => x.Equals(property.Value.Name, StringComparison.CurrentCultureIgnoreCase));
                if (ignoreProperty != null)
                    continue;

                var propertyType = ReflectionHelper.GetPropertyType(property.Value);

                var propertyValue = ReflectionHelper.GetPropertyValue(_data.Item, property.Value);
                ColumnAction(property.Value.Name, propertyValue, propertyType, DataTypes.Object, 0);
            }
        }
    }
}
